﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RATSharp.Collection
{
    /// <summary>
    /// Menu list - collection of all selectable items in menu.
    /// For print juct call ToString.
    /// </summary>
    /// <typeparam name="T">Main items - shown at first</typeparam>
    /// <typeparam name="ADDT">Additional items</typeparam>
    public class MenuList<T, ADDT> : List<T>
    {
        /// <summary>
        /// merged count of items (primary + secondary)
        /// </summary>
        public int fullCount 
    {
        get { return Count + additionalList.Count;  }
    }
        /// <summary>
        /// Menu name
        /// </summary>
        public string name { get; private set; }
        private List<ADDT> additionalList = new List<ADDT>();

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="name">menu name</param>
        public MenuList(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Add additional menu (like stepback) to menu list
        /// </summary>
        /// <param name="item">additional menu item</param>
        public void AddAdditional(ADDT item) {
            additionalList.Add(item);
        }

        /// <summary>
        /// get additional value by index
        /// </summary>
        /// <param name="i">index</param>
        /// <returns>additional value</returns>
        public ADDT GetAdditional(int i) {
            i = i - Count;
            return additionalList.ElementAt(i);
        }

        /// <summary>
        /// Overriden for menu printing
        /// </summary>
        /// <returns>printed menu</returns>
        public override string ToString()
        {
            string value = "";
            if (name != null && name.Length != 0)
            {
                value += (string.Format("--- {0} ---", name) + Environment.NewLine);
            }
            int indexer = 1;
            foreach (T item in this)
            {
                value += (string.Format("{0}) {1}", indexer, item) + Environment.NewLine);
                indexer++;
            }
            foreach (ADDT item in additionalList)
            {
                value += (string.Format("{0}) {1}", indexer, item) + Environment.NewLine);
                indexer++;
            }

            return value;

        }

    }
}
